<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统用户管理</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layui/layuiAdmin/css/admin.css" media="all">
    <style>
        .site-border-default fieldset {
            border-top: 1px solid #eee;
        }
        .layui-inline{


            /* 元素距离上，左都为50% */
            left: 20%;

            /* 让元素的左外边距，上外边距为元素宽高的1/2 注意margin是负距*/
        }
        .layui-card-body{
            overflow-x: scroll;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-radius: 0;border-top: 4px solid #d2d2d2;width: 300px;margin-left: 25%">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div style="display: flex;">
                        <div >
                            <label class="layui-form-label">医生姓名:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="doctorName" id="doctorName" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div style="display: flex;">
                            <label class="layui-form-label">性别:</label>
                            <div class="layui-input-inline">
                                <p class="layui-input" style="margin-top: 8px" id="gender"></p>
                            </div>
                        </div>
                    </div>
                    <div style="display: flex;">
                        <div >
                            <label class="layui-form-label">职称:</label>
                            <div class="layui-input-inline">
                                <p class="layui-input" style="margin-top: 8px" id="professional"></p>

<!--                                <input type="text" name="professional" id="professional" placeholder="请输入用户名" autocomplete="off" class="layui-input">-->
                            </div>
                        </div>
                        <div>
                            <label class="layui-form-label">科室:</label>
                            <div class="layui-input-inline">
                                <p class="layui-input" style="margin-top: 8px" id="department"></p>

<!--                                <input type="text" name="department" id="department" placeholder="请输入用户名" autocomplete="off" class="layui-input">-->
                            </div>
                        </div>


                    </div>
                    <div style="display: flex;">
                        <div >
                            <label class="layui-form-label">从业经验:</label>
                            <div class="layui-input-inline">
                                <p class="layui-input" style="margin-top: 8px" id="medicalExperience"></p>
<!--                                <input type="text" name="medicalExperience" id="medicalExperience" placeholder="请输入用户名" autocomplete="off" class="layui-input">-->
                            </div>
                        </div>
                        <div >
                            <label class="layui-form-label">所属医院:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="hospitalName" id="hospitalName" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>
                    <div style="display: flex;">
                        <div style="display: flex;">
                            <label class="layui-form-label">手机号:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="doctorPhone" id="doctorPhone" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div style="display: flex;">
                            <label class="layui-form-label">资格证:</label>
                            <div class="layui-input-inline">
                                <img   id="certificate" src="" alt="" style="width: 100px;height: 100px;">
                            </div>
                        </div>


                    </div>
                </div>
            </div>
        </div>

        <fieldset class="site-border-default"></fieldset>
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">患者列表</li>
                <li>病例探讨</li>
                <li>患者教育</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-card-body">

                        <table id="LAY-user-manage2" lay-filter="LAY-user-manage2"></table>
                        <script type="text/html" id="table-useradmin-webuser2">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit2"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        </script>
                        <!--状态判断-->
                        <script type="text/html" id="medicalRecTpl">
                            {{#  if(d.medicalRecord == 1){ }}
                            <button class="layui-btn layui-btn-xs">已填写</button>
                            {{#  } else if(d.medicalRecord == 2) { }}
                            <button class="layui-btn layui-btn-primary layui-btn-xs">未填写</button>
                            {{#  } }}

                        </script>

                        <!--  创建时间格式化处理 -->
                        <script type="text/html" id="createTimeTp2">
                            {{formatDate(d.createTime)}}
                        </script>

                        <!--  更新时间格式化处理 -->
                        <script type="text/html" id="updateTimeTpl">
                            {{formatDate(d.updateTime)}}
                        </script>

                        <!--  创建时间格式化处理 -->
                        <script type="text/html" id="lastVisitTpl">
                            {{formatDate(d.lastVisitTime)}}
                        </script>

                        <script type="text/html" id="sexTpl">
                            {{#  if(d.patientSex == 1){ }}
                            <span>男</span>
                            {{#  } else if(d.patientSex == 2) { }}
                            <span>女</span>
                            {{#  } }}
                        </script>

                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-card-body">

                    <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
<!--                        <script type="text/html" id="table-useradmin-webuser">-->
<!--&lt;!&ndash;                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>&ndash;&gt;-->
<!--                        </script>-->

                        <!--状态判断-->
                    <script type="text/html" id="statusTpl">

                        {{#  if(d.status == 1){ }}
                        <button class="layui-btn layui-btn-xs">正常</button>
                        {{#  } else if(d.status == 2) { }}
                        <button class="layui-btn layui-btn-danger layui-btn-xs">冻结</button>
                        {{#  } }}
                    </script>


                    <!--  创建时间格式化处理 -->
                    <script type="text/html" id="createTimeTpl">
                        {{formatDate(d.createTime)}}
                    </script>

                </div>
                </div>
                <div class="layui-tab-item">
<!--                    横向滚动-->
                    <div class="layui-card-body">

                    <table id="LAY-user-manage1" lay-filter="LAY-user-manage1"></table>
                    <script type="text/html" id="table-useradmin-webuser1">
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit1"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    </script>
                    <!--状态判断-->
                    <script type="text/html" id="statusTpl1">

                        {{#  if(d.status == 1){ }}
                        <button class="layui-btn layui-btn-xs">正常</button>
                        {{#  } else if(d.status == 2) { }}
                        <button class="layui-btn layui-btn-danger layui-btn-xs">冻结</button>
                        {{#  } }}
                    </script>


                    <!--  创建时间格式化处理 -->
                    <script type="text/html" id="createTimeTpl1">
                        {{formatDate(d.createTime)}}
                    </script>

                </div></div>

            </div>
        </div>
    </div>


</div>

<script src="../../../layui/layui.js"></script>
<script>
    document.getElementsByName('doctorSex').addEventListener('input', function() {
        var value = this.value;
        if (value === 1) {
            document.getElementById('gender').innerText = '男';
        } else {
            document.getElementById('gender').innerText = '女';
        }
    });
</script>
<script type="text/javascript">

    // 日期格式转换函数
    function formatDate(str) {
        if(str != null){
            var now = new Date(str);
            var year = now.getFullYear();  //取得4位数的年份
            var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
            var date = now.getDate();      //返回日期月份中的天数（1到31）
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds();
            return year + "-" + month + "-" + date +" "+hours+":"+minutes+":"+seconds;
        }
        return "";
    }
</script>
<script type="text/javascript">

    layui.config({
        base: '../../../layui/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer','table','form'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,table = layui.table;
        var doctorSex = localStorage.getItem('doctorSex');
        console.log(doctorSex)
        if (doctorSex == 1){
            document.getElementById('gender').innerText = '男';
        }else{
            document.getElementById('gender').innerText = '女';
        }
        var department = localStorage.getItem('department');
        var professional = localStorage.getItem('professional');
        var medicalExperience = localStorage.getItem('medicalExperience');
        var certificate = localStorage.getItem('certificate');

        document.getElementById('department').innerText = department;
        document.getElementById('professional').innerText = professional;
        document.getElementById('medicalExperience').innerText = medicalExperience;
        document.getElementById('certificate').innerText = certificate;


        //加载table
        table.render({
            elem: '#LAY-user-manage'
            ,url:'http://localhost:8888/caseManager/findAllCase' //后端接口
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
            ,title: '病例探讨信息'
            ,where:{
                doctorId:localStorage.getItem('doctorId')
            }
            ,cols: [[
                // {type: 'checkbox', fixed: 'left'}
                //获得医院数据
                {field:'id', title: '案例id', width:120, sort: true, fixed: 'left'}
                ,{field:'researchtopic', title: '探讨主题', width:120}
                ,{field:'number', title: '人数', width:120}
                ,{field:'buildtime', title: '创建时间', width:180 ,sort: true}
                ,{field:'host', title: '主持人', width:120}
                ,{field:'charge', title: '费用', width:120}
                ,{field:'researchnote', title: '探讨说明', width:120}
                // ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-webuser',width:180}
            ]]
            ,page: {
                curr: 1 //设定初始在第 5 页
                ,limit: 5 //设定初始每页显示 5 条
            },
            limits:[5,10,15,20]
        });

        table.render({
            elem: '#LAY-user-manage1'
            ,url:'http://localhost:8888/patient_education_activity/findActivityAll' //后端接口
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
            ,title: '患教信息'
            ,cols: [[
                // {type: 'checkbox', fixed: 'left'}
                {field:'activityId',title:'ID',width: 80}
                ,{field:'activityName', title:'患教名称',width: 100}
                ,{field:'participantsNumber', title:'参加人数',width: 90}
                ,{field:'liveTime', title:'直播时间',width: 110}
                ,{field:'registrationStartTime', title:'报名开始时间',width: 120}
                ,{field:'registrationEndTime', title:'报名结束时间',width: 120}
                ,{field:'money', title:'活动金额',width: 100}
                ,{field:'compere', title:'主持人',width: 100}
                ,{field:'viewRate', title:'观看率',width: 80}
                ,{field:'status', title:'活动状态',width: 100,templet:'#statusTpl'}
                ,{field:'cancelTime', title:'取消时间',width: 110}
                ,{field:'endTime', title:'结束时间',width: 110}
                ,{field:'cancelReason', title:'取消理由',width: 110}
                ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-webuser1'}
            ]]
            ,page: {
                curr: 1 //设定初始在第 5 页
                ,limit: 5 //设定初始每页显示 5 条
            },
            limits:[5,10,15,20]
        });
        table.render({
            elem: '#LAY-user-manage2'
            ,url:'http://localhost:8888/patient/findPatientAllPatient' //后端接口
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
            ,title: '患者信息'
            ,where: {
                doctorId:localStorage.getItem('doctorId')
            }
            ,cols: [[
                {field:'patientName',title:'患者姓名',width: 100}
                ,{field:'patientSex', title:'患者性别',width: 100,templet: '#sexTpl'}
                ,{field:'patientAddress', title:'现居住地',width: 120}
                ,{field:'lastVisitTime', title:'上次就诊时间',width: 180,templet:'#lastVisitTpl'}
                ,{field:'medicalRecord', title:'病历填写程度',width: 150,templet:'#medicalRecTpl'}
                ,{field:'doctorName', title:'绑定医生',width: 100}
                ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-webuser2',width:300}
            ]]
            ,page: {
                curr: 1 //设定初始在第 5 页
                ,limit: 5 //设定初始每页显示 5 条
            },
            limits:[5,10,15,20]
        });
        //监听行工具事件
        table.on('tool(LAY-user-manage)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '修改病例探讨内容'
                    ,skin: 'layui-layer-molv'
                    ,content: 'editCase.html'
                    ,maxmin: true
                    ,area: ['480px', '400px']
                    ,btn: ['确定', '取消']
                    // 加载弹出层之前获取选中数据，进行回显
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        // 获取编辑表单中用户名元素
                        // 数据回显到弹出的表单中
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

                        body.find("input[name=id]").val(data.id);
                        body.find("input[name=casename]").val(data.casename);
                        body.find("input[name=researchtopic]").val(data.researchtopic);
                        body.find("input[name=continuetime]").val(data.continuetime);
                        // 性别
                        body.find("input[name=chargetype]").val(data.chargetype);
                        body.find("input[name=charge]").val(data.charge);
                        body.find("input[name=researchnote]").val(data.researchnote);
                        body.find("input[name=registrationtime]").val(data.registrationtime);
                        body.find("input[name=registrationendtime]").val(data.registrationendtime);
                        body.find("input[name=host]").val(data.host);
                    }
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"http://localhost:8888/caseManager/edit", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    console.log("主页面",JSON.stringify(res))

                                    layer.msg('修改成功');//弹出提示
                                    table.reload('LAY-user-manage'); //数据刷新
                                    layer.close(index); //关闭弹层


                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });


            }
        });

        table.on('tool(LAY-user-manage1)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit1'){
                layer.open({
                    type: 2
                    ,title: '修改患教内容'
                    ,skin: 'layui-layer-molv'
                    ,content: 'editPaEd.html'
                    ,maxmin: true
                    ,area: ['480px', '400px']
                    ,btn: ['确定', '取消']
                    // 加载弹出层之前获取选中数据，进行回显
                    ,success: function (layero,index){

                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        // 获取编辑表单中用户名元素
                        // 数据回显到弹出的表单中
                        contentWindow.layui.form.val('layuiadmin-form-useradmin', {
                            "activityId": data.activityId
                            ,"activityName": data.activityName
                            ,"participantsNumber": data.participantsNumber
                            ,"liveTime": data.liveTime
                            ,"registrationStartTime": data.registrationStartTime
                            ,"registrationEndTime": data.registrationEndTime
                            ,"money": data.money
                            ,"compere": data.compere
                            ,"viewRate": data.viewRate
                            ,"status": data.status
                            ,"cancelTime": data.cancelTime
                            ,"endTime": data.endTime
                            ,"cancelReason": data.cancelReason
                        });
                    }
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"http://localhost:8888/patient_education_activity/update", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.message);//弹出提示
                                        table.reload('LAY-user-manage1'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.message,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });


            }
        });
        table.on('tool(LAY-user-manage2)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit2'){
                layer.open({
                    type: 2
                    ,title: '修改患者内容'
                    ,skin: 'layui-layer-molv'
                    ,content: 'editPatient.html'
                    ,maxmin: true
                    ,area: ['480px', '400px']
                    ,btn: ['确定', '取消']
                    // 加载弹出层之前获取选中数据，进行回显
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

                        // 获取编辑表单中用户名元素
                        // 数据回显到弹出的表单中
                        contentWindow.layui.form.val('layuiadmin-form-useradmin', {
                            "patientPhone": data.patientPhone
                            ,"patientName": data.patientName
                            ,"patientSex": data.patientSex
                            ,"patientBirthdate": data.patientBirthdate
                            ,"morbidityAge": data.morbidityAge
                            ,"patientAddress": data.patientAddress
                            ,"patientId": data.patientId
                            ,"lastVisitTime":data.lastVisitTime
                            ,"medicalRecord":data.medicalRecord
                            ,"doctorName":data.doctorName
                        });
                        console.log("list中",data.doctorId)
                        localStorage.setItem("doctorId",JSON.stringify(data.doctorId))
                    }
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"http://localhost:8888/patient/update", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.message);//弹出提示
                                        table.reload('LAY-user-manage2'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.message,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });


            }
        });
        $('.layui-btn.layuiadmin-btn-useradmin2').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-btn.layuiadmin-btn-useradmin1').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    });
</script>
</body>
</html>
